package tools

import (
	"fmt"
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
)

var DB *gorm.DB

// 初始化数据源连接
func InitDb() {
	// dsn := "user=postgres password=postgres dbname=postgres sslmode=disable"

	var err error
	dsn := Config.Dsn
	// DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{})
	DB, err = gorm.Open(sqlite.Open(dsn), &gorm.Config{})

	if err != nil {
		panic("failed to connect database")
	}

	fmt.Println("数据库连接成功")
}
